package javagprssrv.Listener;

import javagprssrv.JGS_Param;
import javagprssrv.DataBase.DBConnectionPool;
import javagprssrv.StructClass.structTCPServerSocket;

public class TrdControlTranser_TCP extends java.lang.Thread
{
    private java.net.Socket Client;
    public java.lang.String RemoteIP;
    public int RemotePort;
    java.lang.String LoginTime;
    public boolean isCatchScreen;
    java.lang.String strLine;
    java.util.Vector CommandHistory;
    int idxCommandHistory;
    private boolean isResetApplication;
    private java.io.BufferedReader in;
    private java.io.PrintWriter out;
    private int b;
    boolean isFirstLogin;
    
    public TrdControlTranser_TCP(final java.net.Socket _Client) {
        this.LoginTime = "";
        this.isCatchScreen = false;
        this.strLine = new javagprssrv.Common.CommonParam().strLine;
        this.CommandHistory = new java.util.Vector();
        this.idxCommandHistory = 0;
        this.isResetApplication = false;
        this.in = null;
        this.out = null;
        this.b = -1;
        this.isFirstLogin = true;
        this.Client = _Client;
        try {
            this.Client.setSoTimeout(1800000);
        }
        catch (java.lang.Exception ex) {}
        this.LoginTime = new javagprssrv.Common.DateTime().getDateTime("YYYY年MM月DD日 HH时NN分SS秒");
        this.CommandHistory.clear();
    }
    
    private void CloseMe() {
        if (this.isCatchScreen) {
            synchronized (javagprssrv.JGS_Param.ClientPipe) {
                javagprssrv.JGS_Param.ClientPipe.remove(this.out);
            }
        }
        try {
            this.in.close();
            this.out.close();
            this.interrupt();
        }
        catch (java.lang.Exception ex) {}
    }
    
    private void UserTypeClear(final java.io.PrintWriter PW, final int intCharCounts) {
        for (int i = 0; i < intCharCounts; ++i) {
            PW.write(8);
        }
        for (int i = 0; i < intCharCounts; ++i) {
            PW.write(32);
        }
        for (int i = 0; i < intCharCounts; ++i) {
            PW.write(8);
        }
        PW.flush();
    }
    
    private void DoSendData(final java.io.BufferedReader in, final java.io.PrintWriter out, java.lang.String _strCMD) {
        _strCMD = _strCMD.toUpperCase();
        final java.lang.String[] cmds = _strCMD.split(" ");
        boolean isError = false;
        final int len = cmds.length;
        for (int i = 0; i <= cmds.length - 1; ++i) {
            if (cmds[len - i - 1].trim().equals("")) {
                isError = true;
                break;
            }
        }
        if (!cmds[0].equals("SEND")) {
            isError = true;
        }
        if (!cmds[1].equals("TCP") && !cmds[1].equals("UDP")) {
            isError = true;
        }
        if (isError) {
            out.println(" SEND命令格式错误(注意：只能用一个空格作间隔符！)");
            out.println(" 格式: SEND <Protocol> <IP>:<Port> <Data>");
            out.println(" 例如: SEND TCP 192.0.0.3:7055 41 00 21 82 88 90 80 11 22 80");
            out.println("       SEND UDP 122.194.21.198:9090 88 90 72 72 16");
            out.flush();
            return;
        }
        java.lang.String RIP = "";
        int RPort = -1;
        RIP = cmds[2].split(":")[0];
        RPort = java.lang.Integer.valueOf(cmds[2].split(":")[1]);
        if (cmds[1].equals("TCP")) {
            boolean isFindTerm = false;
            for (int j = 0; j <= javagprssrv.JGS_Param.Terms.size() - 1; ++j) {
                if (javagprssrv.JGS_Param.Terms.elementAt(j).Term_RemoteIP.equals(RIP) && javagprssrv.JGS_Param.Terms.elementAt(j).Term_RemotePort == RPort && javagprssrv.JGS_Param.Terms.elementAt(j).Term_WorkProtocol.equals("TCP")) {
                    isFindTerm = true;
                    break;
                }
            }
            if (!isFindTerm) {
                out.println("对不起，" + RIP + ":" + RPort + "上没有仪表。");
                out.flush();
                return;
            }
            int idx = -1;
            for (int k = 0; k < javagprssrv.JGS_Param.TCPServerSockets.size(); ++k) {
                final javagprssrv.StructClass.structTCPServerSocket TCPServerSokect = (structTCPServerSocket)javagprssrv.JGS_Param.TCPServerSockets.elementAt(k);
                if (TCPServerSokect.RemoteIP.equals(RIP) && TCPServerSokect.RemotePort == RPort) {
                    idx = k;
                    java.lang.String data = "";
                    for (int l = 3; l <= cmds.length - 1; ++l) {
                        data += new javagprssrv.Common.CommonClass().Hex2String(cmds[l]);
                    }
                    try {
                        TCPServerSokect.ServerChannel.write(java.nio.charset.Charset.forName("ISO-8859-1").encode(data));
                        break;
                    }
                    catch (java.lang.Exception e) {
                        out.println("对不起，发送过程中发生错误。");
                        out.println(e.toString());
                        out.flush();
                        return;
                    }
                }
            }
            if (idx == -1) {
                out.println("对不起，没有与" + RIP + ":" + RPort + "建立TCP通道。");
                out.flush();
            }
        }
    }
    
    private void DoDial(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        if (javagprssrv.JGS_Param.COMMTerms.size() == 0) {
            final java.lang.String strResp = "对不起,系统没有找到适合的串口操作设备,无法进行该操作 ！";
            out.println(strResp);
            out.flush();
            return;
        }
        java.lang.String strCMD = _strCMD.trim().toUpperCase();
        java.util.Vector TelNO = new java.util.Vector();
        TelNO.clear();
        if (!strCMD.substring(0, 4).equals("DIAL")) {
            return;
        }
        strCMD = strCMD.substring(4).trim();
        while (strCMD.length() > 0) {
            strCMD = strCMD.trim();
            int idx = strCMD.indexOf(" ");
            if (idx == -1) {
                idx = strCMD.length();
            }
            final java.lang.String telno = strCMD.substring(0, idx);
            strCMD = strCMD.substring(idx).trim();
            TelNO.add(telno);
        }
        java.lang.String strResponse = "您将要拨打电话激活(Dial)： ";
        for (int i = 0; i < TelNO.size(); ++i) {
            strResponse = strResponse + TelNO.elementAt(i) + ",";
        }
        strResponse = strResponse.substring(0, strResponse.length() - 1);
        out.println(strResponse);
        out.flush();
        for (int i = 0; i < TelNO.size(); ++i) {
            javagprssrv.StructClass.structCOMMTask COMMTask = new javagprssrv.StructClass.structCOMMTask();
            COMMTask.TaskType = 0;
            COMMTask.TelNo = java.lang.String.valueOf(TelNO.elementAt(i));
            javagprssrv.JGS_Param.UnDoneCOMMTasks.add(COMMTask);
            COMMTask = null;
        }
        TelNO = null;
    }
    
    private java.lang.String ConvertLong2String(final long longValue, final java.lang.String sp1000) {
        java.lang.String res = "";
        res = java.lang.String.valueOf(longValue);
        for (int strLength = res.length(), i = 0; i < strLength; ++i) {
            if (i % 3 == 0 && i > 0) {
                res = res.substring(0, strLength - i) + sp1000 + res.substring(strLength - i, res.length());
            }
        }
        return res;
    }
    
    private void DoShow(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        java.lang.String strParam = "" + this.strLine;
        final long totalM = java.lang.Runtime.getRuntime().totalMemory() / 1024L;
        final long freeM = java.lang.Runtime.getRuntime().freeMemory() / 1024L;
        final java.lang.String totalM_freeM = java.lang.String.valueOf(totalM) + " - " + java.lang.String.valueOf(freeM) + " = ";
        strParam = strParam + "ApplicationUsedMemory = " + totalM_freeM + java.lang.String.valueOf(totalM - freeM) + " KBytes" + this.strLine + this.strLine;
        strParam = strParam + "JGP_Param.ClientPipe.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.ClientPipe.size()) + this.strLine;
        strParam = strParam + "JGP_Param.TCP_Terms.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.TCP_Terms.size()) + this.strLine;
        for (int i = 0; i < javagprssrv.JGS_Param.TCP_Terms.size(); ++i) {
            java.lang.String str = "";
            str = str + "TermType=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_Type + ", ";
            str = str + "IP:Port=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_RemoteIP + ":" + java.lang.String.valueOf(javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_RemotePort) + ", ";
            str = str + "YBH=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_SerialNo + ", ";
            str = str + "TelNO=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_TelNo + ", ";
            str = str + "WYM=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_WYM + ", ";
            str = str + "TermNO=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_TermNo + ", ";
            str = str + "ZB=" + javagprssrv.JGS_Param.TCP_Terms.elementAt(i).Term_ZB + " ";
            strParam = strParam + "    JGP_Param.TCP_Terms(" + i + ")  >>   " + str + this.strLine;
        }
        strParam = strParam + "Tasks.size() / TempTasks.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.Tasks.size()) + " / " + java.lang.String.valueOf(javagprssrv.JGS_Param.TempTasks.size()) + this.strLine;
        for (int i = 0; i < javagprssrv.JGS_Param.DBConnectionS.size(); ++i) {
            final int ConnectionPool_SRC_Size = javagprssrv.JGS_Param.DBConnectionS.elementAt(i).ConnectionPool.size();
            final int StatementPool_SRC_Size = ((DBConnectionPool)javagprssrv.JGS_Param.DBConnectionS.elementAt(i)).StatementPool.size();
            strParam = strParam + "    JGP_Param.DBConnectionS(" + i + ") = Conn : " + java.lang.String.valueOf(ConnectionPool_SRC_Size) + " , Stmt : " + java.lang.String.valueOf(StatementPool_SRC_Size) + this.strLine;
        }
        strParam = strParam + "JGP_Param.UnDoneDBActionRecvDatas.size / JGP_Param.UnDoneRecvDatas.size() = " + javagprssrv.JGS_Param.UnDoneDBActionRecvDatas.size() + " / " + javagprssrv.JGS_Param.UnDoneRecvDatas.size() + this.strLine;
        strParam = strParam + "Total DataAnalyse(DB) Threads / BUSY Threads = " + javagprssrv.JGS_Param._TrdDataAnalyse_DBAction_Count + " / " + javagprssrv.JGS_Param.countDataAnalyse_DBAction_BusyThread + this.strLine;
        strParam = strParam + "JGP_Param.UnTransmitRecvDatas.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.UnTransmitRecvDatas.size()) + this.strLine;
        strParam = strParam + "JGP_Param.TCPServerSockets.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.TCPServerSockets.size()) + this.strLine;
        int TCPServerSocketCount = javagprssrv.JGS_Param.TCPServerSockets.size();
        if (TCPServerSocketCount > 100) {
            TCPServerSocketCount = 100;
        }
        for (int j = 0; j < TCPServerSocketCount; ++j) {
            strParam = strParam + "    RemoteIP = " + ((structTCPServerSocket)javagprssrv.JGS_Param.TCPServerSockets.elementAt(j)).RemoteIP;
            strParam = strParam + "   ,RemotePort = " + ((structTCPServerSocket)javagprssrv.JGS_Param.TCPServerSockets.elementAt(j)).RemotePort;
            strParam += this.strLine;
        }
        strParam = strParam + "JGP_Param.UnSavedRecvData_TCP.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.UnSavedRecvData_TCP.size()) + this.strLine;
        strParam = strParam + "JGP_Param.UnSavedRecvData_UDP.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.UnSavedRecvData_UDP.size()) + this.strLine;
        strParam = strParam + "JGP_Param.UnDBSavedSQLString.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.UnSavedDBSQLString.size());
        strParam = strParam + " ( Success : " + java.lang.String.valueOf(javagprssrv.JGS_Param.countSavedSQL_Success) + ", Failure : " + java.lang.String.valueOf(javagprssrv.JGS_Param.countSavedSQL_Failure) + ")" + this.strLine;
        strParam = strParam + "IATasks.size()  = " + java.lang.String.valueOf(javagprssrv.JGS_Param.IATasks.size()) + this.strLine;
        strParam = strParam + "JGP_Param.JSSJClients.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.JSSJClients.size()) + this.strLine;
        int JSSJClientsCount = javagprssrv.JGS_Param.JSSJClients.size();
        if (JSSJClientsCount > 100) {
            JSSJClientsCount = 100;
        }
        for (int k = 0; k < JSSJClientsCount; ++k) {
            strParam = strParam + "    ClientIP = " + ((structTCPServerSocket)javagprssrv.JGS_Param.JSSJClients.elementAt(k)).RemoteIP;
            strParam = strParam + "   ,ClientPort = " + ((structTCPServerSocket)javagprssrv.JGS_Param.JSSJClients.elementAt(k)).RemotePort;
            strParam += this.strLine;
        }
        strParam = strParam + "JGP_Param.UDPServerSockets.size() = " + java.lang.String.valueOf(javagprssrv.JGS_Param.UDPServerSockets.size()) + this.strLine + this.strLine;
        strParam = strParam + "TOTAL Data Throughput Bytes = ( TCP ) " + this.ConvertLong2String(javagprssrv.JGS_Param.countReceiveData_TCP, ",") + " / " + this.ConvertLong2String(javagprssrv.JGS_Param.timesReceiveData_TCP, ",") + " + ( UDP ) " + this.ConvertLong2String(javagprssrv.JGS_Param.countReceiveData_UDP, ",") + " / " + this.ConvertLong2String(javagprssrv.JGS_Param.timesReceiveData_UDP, ",") + " = " + this.ConvertLong2String(javagprssrv.JGS_Param.countReceiveData_All, ",") + this.strLine;
        out.println(strParam);
        out.flush();
    }
    
    private void DoShowINI(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        java.util.Vector<java.lang.String> txtFile = javagprssrv.JGS_Param.getTXTFile(javagprssrv.JGS_Param.INIFileName);
        for (int i = 0; i < txtFile.size(); ++i) {
            out.println(txtFile.elementAt(i));
        }
        out.flush();
        txtFile.clear();
        txtFile = null;
    }
    
    private void DoShowTerms(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        out.println("          仪表号          通讯方式          远端IP          远端Port           唯一码              ");
        out.println("======================================================================================================");
        for (int i = 0; i <= javagprssrv.JGS_Param.Terms.size() - 1; ++i) {
            java.lang.String s = "";
            s = "          " + javagprssrv.JGS_Param.Terms.elementAt(i).Term_TermNo + "      ";
            s = s + javagprssrv.JGS_Param.Terms.elementAt(i).Term_WorkProtocol + "      ";
            s = s + javagprssrv.JGS_Param.Terms.elementAt(i).Term_RemoteIP + "      ";
            s = s + javagprssrv.JGS_Param.Terms.elementAt(i).Term_RemotePort + "      ";
            s = s + javagprssrv.JGS_Param.Terms.elementAt(i).Term_AsynString + "      ";
            out.println(s);
        }
        out.flush();
    }
    
    private void DoShowTermStruct(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        java.lang.String strParam = "" + this.strLine;
        javagprssrv.StructClass.structTerm Term = new javagprssrv.StructClass.structTerm();
        java.lang.reflect.Field[] f = Term.getClass().getFields();
        for (int idxField = 0; idxField < f.length; ++idxField) {
            java.lang.String s = "";
            if (idxField < 9) {
                s = "    0" + java.lang.String.valueOf(idxField + 1) + ".    名 称 = " + f[idxField].getName() + "   ( " + f[idxField].getType().getName() + " )";
            }
            else {
                s = "    " + java.lang.String.valueOf(idxField + 1) + ".    名 称 = " + f[idxField].getName() + "   ( " + f[idxField].getType().getName() + " )";
            }
            strParam = strParam + s + this.strLine;
        }
        out.println(strParam);
        out.flush();
        Term = null;
        f = null;
    }
    
    private void DoShowTaskStruct(final java.io.BufferedReader in, final java.io.PrintWriter out, final java.lang.String _strCMD) {
        java.lang.String strParam = "" + this.strLine;
        javagprssrv.StructClass.structTask Task = new javagprssrv.StructClass.structTask();
        java.lang.reflect.Field[] f = Task.getClass().getFields();
        for (int idxField = 0; idxField < f.length; ++idxField) {
            java.lang.String s = "";
            if (idxField < 9) {
                s = "    0" + java.lang.String.valueOf(idxField + 1) + ".    名 称 = " + f[idxField].getName() + "   ( " + f[idxField].getType().getName() + " )";
            }
            else {
                s = "    " + java.lang.String.valueOf(idxField + 1) + ".    名 称 = " + f[idxField].getName() + "   ( " + f[idxField].getType().getName() + " )";
            }
            strParam = strParam + s + this.strLine;
        }
        out.println(strParam);
        out.flush();
        Task = null;
        f = null;
    }
    
    private void ShowStart(final java.io.PrintWriter pw) {
        pw.println(" ");
        pw.println(" ");
        pw.println(" ");
        pw.println("  系统名称 :     " + javagprssrv.JGS_Param.AppName);
        pw.println("  系统版本 :     " + javagprssrv.JGS_Param.AppVersion);
        pw.println("  启动时间 :     " + javagprssrv.JGS_Param.AppStartTime);
        pw.println("");
        pw.println("");
        pw.println("");
    }
    
    @java.lang.Override
    public void run() {
        java.lang.String inputString = "";
        try {
            this.in = new java.io.BufferedReader(new java.io.InputStreamReader(this.Client.getInputStream()));
            this.ShowStart(this.out = new java.io.PrintWriter(this.Client.getOutputStream()));
            this.out.println(javagprssrv.JGS_Param.AppName + "--控制模式，欢迎您！(请使用\"help\"或\"?\"查看帮助)");
            this.out.flush();
            if (this.isFirstLogin) {
                synchronized (javagprssrv.JGS_Param.ClientPipe) {
                    javagprssrv.JGS_Param.ClientPipe.add(this.out);
                }
                this.isCatchScreen = true;
                this.isFirstLogin = false;
            }
            java.lang.String lastCommand = "?";
            while (true) {
                try {
                    java.lang.Thread.sleep(20L);
                }
                catch (java.lang.Exception ex) {}
                this.RemoteIP = this.Client.getInetAddress().getHostAddress();
                this.RemotePort = this.Client.getPort();
                this.out.print(">");
                this.out.flush();
                int charLast3 = 0;
                int charLast4 = 0;
                int charLast5 = 0;
                inputString = "";
                this.idxCommandHistory = 0;
                while (true) {
                    try {
                        this.b = this.in.read();
                    }
                    catch (java.lang.Exception e2) {
                        this.b = -1;
                        return;
                    }
                    if (this.b == -1) {
                        this.CloseMe();
                        break;
                    }
                    if (this.b == 8) {
                        if (inputString.length() >= 1) {
                            inputString = inputString.substring(0, inputString.length() - 1);
                            this.UserTypeClear(this.out, 100);
                            this.out.write(">" + inputString);
                            this.out.flush();
                        }
                        else {
                            this.UserTypeClear(this.out, 100);
                            this.out.write(">" + inputString);
                            this.out.flush();
                        }
                    }
                    else if (this.b == 9 || (charLast3 == 27 && charLast4 == 79 && charLast5 == 80) || (charLast3 == 27 && charLast4 == 79 && charLast5 == 81) || (charLast3 == 27 && charLast4 == 79 && charLast5 == 82) || (charLast3 == 27 && charLast4 == 79 && charLast5 == 83)) {
                        charLast3 = 0;
                        charLast4 = 0;
                        charLast5 = 0;
                        this.UserTypeClear(this.out, 100);
                        this.out.write(">" + inputString);
                        this.out.flush();
                    }
                    else {
                        inputString += (char)this.b;
                        charLast3 = charLast4;
                        charLast4 = charLast5;
                        charLast5 = this.b;
                    }
                    if (charLast3 == 27 && charLast4 == 91 && charLast5 == 65) {
                        this.UserTypeClear(this.out, 100);
                        java.lang.String strCommand = "";
                        if (this.CommandHistory.size() > 0) {
                            ++this.idxCommandHistory;
                            if (this.CommandHistory.size() <= this.idxCommandHistory) {
                                this.idxCommandHistory = this.CommandHistory.size();
                            }
                            strCommand = (inputString = (String)this.CommandHistory.elementAt(this.CommandHistory.size() - this.idxCommandHistory));
                        }
                        else {
                            strCommand = (inputString = "");
                        }
                        charLast3 = 0;
                        charLast4 = 0;
                        charLast5 = 0;
                        this.out.write(">" + inputString);
                        this.out.flush();
                    }
                    if (charLast3 == 27 && charLast4 == 91 && charLast5 == 66) {
                        this.UserTypeClear(this.out, 100);
                        java.lang.String strCommand = "";
                        if (this.CommandHistory.size() > 0) {
                            --this.idxCommandHistory;
                            if (0 >= this.idxCommandHistory) {
                                this.idxCommandHistory = 0;
                            }
                            strCommand = (inputString = (String)this.CommandHistory.elementAt(this.CommandHistory.size() - this.idxCommandHistory - 1));
                        }
                        else {
                            strCommand = (inputString = "");
                        }
                        charLast3 = 0;
                        charLast4 = 0;
                        charLast5 = 0;
                        this.out.write(">" + inputString);
                        this.out.flush();
                    }
                    if (charLast4 == 13 && charLast5 == 10) {
                        inputString = inputString.substring(0, inputString.length() - 2);
                        break;
                    }
                }
                java.lang.String str;
                java.lang.String originalStr = str = inputString;
                if (str.length() == 0) {
                    if (this.isCatchScreen) {
                        str = "NO CATCH SCREEN";
                    }
                    else {
                        str = lastCommand;
                    }
                    this.out.println(str);
                    this.out.flush();
                }
                java.lang.String s = "[P=TCP,T=CTRL,S=";
                s = s + this.Client.getInetAddress().getHostAddress() + ":";
                s = s + java.lang.Integer.valueOf(this.Client.getPort()).toString().trim() + "] ";
                new javagprssrv.Log().ShowLog(s + str, true, true);
                str = str.toUpperCase().trim();
                java.lang.Boolean isRightCommand = false;
                if (str.equals("EXIT") || str.equals("QUIT")) {
                    break;
                }
                if (str.equals("HELP") || str.equals("?")) {
                    isRightCommand = true;
                    java.lang.String strResponse = "您可以使用以下的命令(带*表示该功能正在完善中)：" + this.strLine;
                    strResponse = strResponse + "  ?,help                       :帮助;" + this.strLine;
                    strResponse = strResponse + "  add task                     :手工添加任务(可使用add task /?查看帮助);" + this.strLine;
                    strResponse = strResponse + "  add task /?                  :关于手工添加任务的帮助;" + this.strLine;
                    strResponse = strResponse + "  config                       :(*)进行系统参数的设置;" + this.strLine;
                    strResponse = strResponse + "  exit,quit                    :退出控制模式;" + this.strLine;
                    strResponse = strResponse + "  gc                           :使用JVM清除垃圾;" + this.strLine;
                    strResponse = strResponse + "  language china               :(*)设置帮助用语言为中文;" + this.strLine;
                    strResponse = strResponse + "  language english             :(*)设置帮助用语言为英文;" + this.strLine;
                    strResponse = strResponse + "  restart application          :服务器核心程序重新启动;" + this.strLine;
                    strResponse = strResponse + "  restart computer             :(*)服务器电脑重新启动(需要管理员权限);" + this.strLine;
                    strResponse = strResponse + "  send <proto> <IP>:<p> data   :发送数据;" + this.strLine;
                    strResponse = strResponse + "  show                         :查看所有系统参数;" + this.strLine;
                    strResponse = strResponse + "  show ini                     :查看INI配置文件;" + this.strLine;
                    strResponse = strResponse + "  show starttime               :查看系统启动日期和时间;" + this.strLine;
                    strResponse = strResponse + "  show version                 :查看核心程序版本;" + this.strLine;
                    strResponse = strResponse + "  show terms                   :查看所有在线仪表;" + this.strLine;
                    strResponse = strResponse + "  show term struct             :查看Term数组结构 (针对GetLoadTermSQLString());" + this.strLine;
                    strResponse = strResponse + "  show task struct             :查看Task数组结构 (针对TaskAction.js);" + this.strLine;
                    strResponse = strResponse + "  server show log              :服务器端显示(/关闭)日志;" + this.strLine;
                    strResponse = strResponse + "  dial <tel1> <tel2> <tel3>... :进行拨打电话的测试;" + this.strLine;
                    strResponse = strResponse + "  catch screen                 :获得服务器上的日志同步显示权;" + this.strLine;
                    strResponse += "  who am i,whoami              :显示您的IP和端口信息;";
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("SHOW STARTTIME")) {
                    isRightCommand = true;
                    final java.lang.String strResponse = "系统本次启动时间为：" + javagprssrv.JGS_Param.AppStartTime;
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("GC")) {
                    isRightCommand = true;
                    java.lang.System.gc();
                    java.lang.System.runFinalization();
                    final java.lang.String strResponse = "GC()+runFinalization() : 成功执行。";
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("SERVER SHOW LOG")) {
                    isRightCommand = true;
                    java.lang.System.gc();
                    java.lang.String strResponse = "";
                    if (javagprssrv.JGS_Param.isServerShowLog) {
                        strResponse = "服务器端显示日志状态 = “是” ，系统将 “关闭” 日志的显示。";
                    }
                    else {
                        strResponse = "服务器端显示日志状态 = “否” ，系统将 “打开” 日志的显示。";
                    }
                    javagprssrv.JGS_Param.isServerShowLog = !javagprssrv.JGS_Param.isServerShowLog;
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("CATCH SCREEN")) {
                    isRightCommand = true;
                    if (!this.isCatchScreen) {
                        final java.lang.String strResponse = "CATCH SCREEN 成功执行，输入NO CATCH SCREEN回车取消同步显示。";
                        this.out.println(strResponse);
                        this.out.flush();
                        synchronized (javagprssrv.JGS_Param.ClientPipe) {
                            javagprssrv.JGS_Param.ClientPipe.add(this.out);
                        }
                        this.isCatchScreen = true;
                    }
                }
                if (str.equals("NO CATCH SCREEN")) {
                    isRightCommand = true;
                    if (this.isCatchScreen) {
                        final java.lang.String strResponse = "NO CATCH SCREEN 成功执行，已取消同步显示。";
                        this.out.println(strResponse);
                        this.out.flush();
                        synchronized (javagprssrv.JGS_Param.ClientPipe) {
                            javagprssrv.JGS_Param.ClientPipe.remove(this.out);
                        }
                        this.isCatchScreen = false;
                    }
                }
                if (str.equals("SHOW VERSION")) {
                    isRightCommand = true;
                    final java.lang.String strResponse = "系统当前版本为：" + javagprssrv.JGS_Param.AppVersion;
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("RESTART APPLICATION")) {
                    isRightCommand = true;
                    final java.lang.String strResponse = "秒后即将为您重启动核心程序。";
                    this.isResetApplication = true;
                    for (int intResetSeconds = 10, i = 0; i < intResetSeconds; ++i) {
                        this.UserTypeClear(this.out, 100);
                        this.out.print("    " + java.lang.String.valueOf(intResetSeconds - i) + strResponse);
                        this.out.flush();
                        java.lang.Thread.sleep(1000L);
                    }
                    this.out.println("\r\n核心程序重启动中，请稍候......");
                    this.out.flush();
                    new javagprssrv.Main();
                    javagprssrv.Main.main(null);
                }
                if (str.length() >= 4 && str.substring(0, 4).equals("DIAL")) {
                    isRightCommand = true;
                    this.DoDial(this.in, this.out, str);
                }
                if (str.length() >= 4 && str.substring(0, 4).equals("SEND")) {
                    isRightCommand = true;
                    this.DoSendData(this.in, this.out, str);
                }
                if (str.equals("SHOW TERM STRUCT")) {
                    isRightCommand = true;
                    this.DoShowTermStruct(this.in, this.out, str);
                }
                if (str.equals("SHOW TERMS")) {
                    isRightCommand = true;
                    this.DoShowTerms(this.in, this.out, str);
                }
                if (str.equals("SHOW TASK STRUCT")) {
                    isRightCommand = true;
                    this.DoShowTaskStruct(this.in, this.out, str);
                }
                if (str.equals("SHOW")) {
                    isRightCommand = true;
                    this.DoShow(this.in, this.out, str);
                }
                if (str.equals("SHOW INI")) {
                    isRightCommand = true;
                    this.DoShowINI(this.in, this.out, str);
                }
                if (str.equals("WHO AM I") || str.equals("WHOAMI")) {
                    isRightCommand = true;
                    java.lang.String strResponse = "您的IP=" + this.RemoteIP + "，端口=" + java.lang.Integer.valueOf(this.RemotePort).toString() + this.strLine;
                    strResponse = strResponse + "您的登录时间为:" + this.LoginTime;
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (str.equals("ADD TASK /?")) {
                    isRightCommand = true;
                    java.lang.String strResponse = "您可以按以下命令使用“Add Task”：" + this.strLine;
                    strResponse = strResponse + "Add Task Creator,TermTelNO,TermNO,strCommandS,CanBeAsyn,TaskAsynTelNO,SchemeDateTime" + this.strLine;
                    strResponse = strResponse + "   Creator          :创建者，字符类型" + this.strLine;
                    strResponse = strResponse + "   TermTelNO        :仪表所使用的手机卡号，字符类型" + this.strLine;
                    strResponse = strResponse + "   TermNO           :仪表号，字符类型" + this.strLine;
                    strResponse = strResponse + "   strCommandS      :与仪表通讯的指令，字符类型" + this.strLine;
                    strResponse = strResponse + "   CanBeAsyn        :是否可以异步，True或者False" + this.strLine;
                    strResponse = strResponse + "   TaskAsynTelNO    :仪表的唯一码(如果有的话)，字符类型" + this.strLine;
                    strResponse += "   SchemeDateTime   :计划执行该任务的时间，格式YYYY-MM-DD HH:NN:SS，字符类型";
                    this.out.println(strResponse);
                    this.out.flush();
                }
                if (this.CommandHistory.indexOf(originalStr) == -1) {
                    if (this.CommandHistory.size() == 50) {
                        this.CommandHistory.remove(0);
                    }
                    this.CommandHistory.add(originalStr);
                }
                else {
                    this.CommandHistory.remove(originalStr);
                    this.CommandHistory.add(originalStr);
                }
                originalStr = null;
                if (!isRightCommand) {
                    final java.lang.String strResponse = "您输入的\"" + originalStr + "\"命令不能被解释，请您确认。";
                    this.out.println(strResponse);
                    this.out.flush();
                }
                else {
                    lastCommand = str;
                }
            }
            java.lang.Boolean isRightCommand = true;
            this.Client.close();
            javagprssrv.JGS_Param.ClientPipe.remove(this.out);
        }
        catch (java.lang.Exception e) {
            e.printStackTrace();
            final java.lang.String strError = e.getMessage();
            if (strError.indexOf("Read timed out") > -1) {
                this.CloseMe();
            }
        }
    }
}
